home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ham Radio 2000
/
Ham Radio 2000.iso
/
ham2000
/
tcp_ip
/
os2
/
pmnos11s
/
junk.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-30
|
2KB
|
83 lines
/* Read through FTPUSERS looking for user record
* Returns line which matches username, or NULLCHAR when no match.
* Each of the other variables must be copied before freeing the line.
*/
char *
userlookup(username,password,directory,permission,ip_address)
char *username;
char **password;
char **directory;
int *permission;
int32 *ip_address;
{
FILE *fp;
char *buf;
char *cp;
/* Subroutine for logging in the user whose name is name and password is pass.
The buffer path should be long enough to keep a line from the userfile.
If pwdignore is true, the password check will be overridden.
The return value is the permissions field or -1 if the login failed.
Path is set to point at the path field, and pwdignore will be true if no
particular password was needed for this user.
if((fp = fopen(Userfile,READ_TEXT)) == NULLFILE)
/* Userfile doesn't exist */
return NULLCHAR;
buf = mallocw(128);
while ( fgets(buf,128,fp) != NULLCHAR ){
if(*buf == '#')
continue; /* Comment */
if((cp = strchr(buf,' ')) == NULLCHAR)
/* Bogus entry */
continue;
*cp++ = '\0'; /* Now points to password */
if( stricmp(username,buf) == 0 )
break; /* Found user */
}
if(feof(fp)){
/* username not found in file */
fclose(fp);
free(buf);
return NULLCHAR;
}
fclose(fp);
if ( password != NULL )
*password = cp;
/* Look for space after password field in file */
if((cp = strchr(cp,' ')) == NULLCHAR) {
/* Invalid file entry */
free(buf);
return NULLCHAR;
}
*cp++ = '\0'; /* Now points to directory field */
if ( directory != NULL )
*directory = cp;
if((cp = strchr(cp,' ')) == NULLCHAR) {
/* Permission field missing */
free(buf);
return NULLCHAR;
}
*cp++ = '\0'; /* now points to permission field */
if ( permission != NULL )
*permission = (int)strtol( cp, NULLCHARP, 0 );
if((cp = strchr(cp,' ')) == NULLCHAR) {
/* IP address missing */
if ( ip_address != NULL )
*ip_address = 0L;
} else {
*cp++ = '\0'; /* now points at IP address field */
if ( ip_address != NULL )
*ip_address = resolve( cp );
}
return buf;
}